{% extends '_base_create_update.html' %}

{% block top_css %}
    {{ super() }}

    <!--Treeview-->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='plugins/bootstrap-treeview/css/bootstrap-treeview.min.css') }}">
    <!--bees-->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bees.css') }}">

{% endblock %}


<!-- Content head -->
{% block head_title %}
    作业中心
{% endblock %}

{% block head_nav %}
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i></a></li>
        <li><a href="#">定时任务</a></li>
        <li class="active">定时调度</li>
    </ol>
{% endblock %}

<!-- Content body -->
{% block body_title %}
    修改定时调度
{% endblock %}

{% block body_form %}
    <form name="crontabForm" action="" class="form-horizontal">
        <div class="panel-body">
            <p class="bord-btm pad-ver text-main text-bold">基本信息</p>

            <div class="row">
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>分</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="minute" value="{{ minute }}" placeholder="请输入需要调度的分钟" data-rule="调度的分钟: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>时</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="hour" value="{{ hour }}" placeholder="请输入需要调度的小时" data-rule="调度的小时: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>天</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="day_of_month" value="{{ day_of_month }}" placeholder="请输入需要调度的日期" data-rule="调度的月份: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>月</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="month_of_year" value="{{ month_of_year }}" placeholder="请输入需要调度的月份" data-rule="调度的年份: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>周</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="day_of_week" value="{{ day_of_week }}" placeholder="请输入需要调度的星期" data-rule="调度的星期: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>

        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-6 col-sm-offset-6">
                    <div class="col-sm-7 col-sm-offset-3">
                        <button class="btn btn-mint pull-right" type="submit">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
{% endblock %}



{% block buttom_js %}
    {{ super() }}
    <!--bees-->
    <script src="{{ url_for('static', filename='js/bees.js') }}"></script>
    <!--Treeview-->
    <script src="{{ url_for('static', filename='plugins/bootstrap-treeview/js/bootstrap-treeview.min.js') }}"></script>

    <script type="text/javascript">

        $(function () {
            var $formEle = $('form[name="crontabForm"]');
            bees.niceValidate($formEle);
            $formEle.on("valid.form", function () {
                setAjaxCSRFToken();

                $.ajax({
                    type: 'post',
                    url: '{{ url_for("tasks.crontab-update", pk=default_pk) }}'.replace(bees.defaultPK, '{{ id }}'),
                    data : $formEle.serialize(),
                    success: function (result) {
                        if (result.code != 200) {
                            $formEle.find('*[name='+ result.data.field +']').focus().addClass('has-error');
                            bees.tipError({
                                message: result.data.message
                            });
                        }else {
                            bees.tipInfo({
                                message: '修改成功'
                            });
                            window.location.href = '{{ url_for("tasks.crontab-list") }}'
                        }
                    }
                });
            })
        })

    </script>

{% endblock %}
